package com.redpack.redpost.struts.action.admin;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.admin.multimediaForm;
import com.redpack.redpost.util.dao.adminDAO;
import com.redpack.redpost.util.to.generalUtil;
import com.redpack.redpost.util.to.multimediaTo;

public class agregamultimedia extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		boolean logginVal = generalUtil.isLoggedInAdmin(request);
		if(logginVal!=true){
			return mapping.findForward("noLogin") ;
		}
		
		multimediaForm f = (multimediaForm)form;
		String cve_multimedia = "0", nombre_sel = "", slide_sel="",teaser_sel="",link_sel="",categoria_sel="",order_sel="0";
		
		if( f != null ){
			if( f.getAcc().equals("1") && f.getCve_multimedia() > 0 ){
				multimediaTo multimedia_info = adminDAO.getMultimedia( f.getCve_multimedia() );
				cve_multimedia = ""+f.getCve_multimedia();
				nombre_sel = multimedia_info.getNombre();
				slide_sel=""+multimedia_info.getSlide();
				teaser_sel=""+multimedia_info.getTeaser();
				link_sel = multimedia_info.getLink();
				categoria_sel = multimedia_info.getCategoria();
				order_sel = ""+multimedia_info.getOrden();
			}
		}
		
		List slides = new ArrayList();
		List teasers = new ArrayList();
		try {
			slides = adminDAO.getSlides();
			teasers = adminDAO.getTeaser();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("slides", slides);
		request.setAttribute("teasers", teasers);
		
		request.setAttribute("cve_multimedia", cve_multimedia);
		request.setAttribute("nombre_sel", nombre_sel);
		request.setAttribute("slide_sel", slide_sel);
		request.setAttribute("teaser_sel", teaser_sel);
		request.setAttribute("link_sel", link_sel);
		request.setAttribute("categoria_sel", categoria_sel);
		request.setAttribute("order_sel", order_sel);
		
		return mapping.findForward("success") ;
	}

}